package com.smz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.smz.entity.Site;
import com.smz.service.SiteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
public class SiteController {


    @Autowired
    private SiteService siteService;

    @GetMapping("sites/{current}/{size}")
    public ResponseEntity<IPage<Site>> findByPage(@PathVariable("current")Integer current,
                                                  @PathVariable("size")Integer size){
        IPage<Site> byPage = siteService.findByPage(current, size);
        return ResponseEntity.ok(byPage);
    }


    @PostMapping("sites")
    public ResponseEntity<String>addSite(@RequestBody Site site){
        siteService.addSite(site);
        return ResponseEntity.ok("ok");
    }

    @PutMapping("sites")
    public ResponseEntity<String>modifySite(@RequestBody Site site){
        siteService.modifySite(site);
        return ResponseEntity.ok("ok");
    }
    @DeleteMapping("sites/{id}")
    public ResponseEntity<String>deleteSite(@PathVariable("id")Integer id){
        siteService.removeSite(id);
        return ResponseEntity.ok("ok");
    }


}
